package pl.wr.particle.impl.quantum;

import java.util.Arrays;

import pl.wr.core.ISpace;
import pl.wr.core.physics.IPhysicalObject;
import pl.wr.particle.def.matter.IParticle;
import pl.wr.particle.impl.Particle;

/**
 * @version 1.0
 * @author wieslaw.rodak
 *
 */
public class PhysicalSpace implements ISpace{
	
	private final IPhysicalObject[] particles = new Particle[100];
	private int particlesCount = 0;
	
	protected PhysicalSpace(){};
	
	/**
	 *
	 */
	private static class SingletonHolder { 
        private static final PhysicalSpace INSTANCE = new PhysicalSpace();
    }
	
	public static PhysicalSpace getSpace() {
        return SingletonHolder.INSTANCE;
    }

	public IParticle[] getParticles() {
		return (IParticle[]) particles;
	}

	public int addParticles(IParticle[] particles) {
		
		IParticle iParticle = null;
		
		for (int i = 0; i < particles.length; i++) {
			iParticle = particles[i];
			this.particles[particlesCount] = iParticle;
			particlesCount ++;
		}
		return particlesCount - 1;
	}

	@Override
	public String toString() {
		return Arrays.toString(particles).replace("null, ", "").replace(", null", "");
	}
	
}
